package third.lib.utils;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

public class EncryptUtils {
    public static String MD5Encode(String content) {
        String md5Str = "";
        try{
            // 创建一个MessageDigest实例:
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(content.getBytes("UTF-8"));
            byte[] result = md.digest(); // 16 bytes: 68e109f0f40ca72a15e05cc22786f8e6
            md5Str = new BigInteger(1, result).toString(16);
            for (int i = 0; i < 32 - md5Str.length(); i++) {
                md5Str = "0" + md5Str;
            }
        }catch (NoSuchAlgorithmException ex){
            ex.printStackTrace();
        }catch (UnsupportedEncodingException ex1){
            ex1.printStackTrace();
        }
        return md5Str;
    }

    public static String uuid(){
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
}
